//
//  AppDelegate.m
//  01-UIView、UIWindow
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "UIView+ChangeFrame.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // 程序的组成结构
    // 1 main.m 主要实现了程序的正常运行
    // 2 AppDelegate 程序的执行者,签订了UIApplicationDelegate协议
    // 注意:AppDelegate就是一个普通的类, 签订了UIApplicationDelegate协议, 才有了很多协议方法
    // 3 ViewController 视图控制器 主要负责视图管理
    // 4 Main.storyboard(视图管理) LaunchScreen.stroyboard(负责启动页),可视化管理 Xcode 7以前LaunchScreen.xib
    // 5 Assets.xcassets 主要用来管理图片素材 Xcode 7 以前叫Images.xcassets
    // 6 Info.plist 工程配置文件
    
    // 模拟器
    // command + 1~5 改变模拟器大小
    // commadn + ← → 横竖屏
    
    // iOS概述
    // iOS错误的写法 IOS ios Ios
    
    // 1 UIWindow (程序中, 只有一个主Window)
    //  1> 取消程序的可视化入口(Main.sb)
    //  2> 创建主window对象
    //  创建主window, 使其大小与屏幕一样
    // UIScreen 系统屏幕类
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    // 让window 成为主窗口并显示
    [_window makeKeyAndVisible];
    // Xcode 7以后, 必须设置rootViewController, 否则, 在方法结束时, 会崩溃
    ViewController *root = [[ViewController alloc] init];
    // 设置window的主窗口
    _window.rootViewController = root;
    //  3> UIWindow 继承于 UIView
    
    /*
    // 2 UIView(与NSObject相似, 是UI阶段的根类, 大部分UI控件继承于UIView)
    // 学习新类
    //  1> 新类包含哪些初始化方法
    //  2> 包含哪些行为(方法)和特征(属性)
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
    view.backgroundColor = [UIColor greenColor];
    [_window addSubview:view];
    // 遇到UIView的子类 都可以用以上方式创建和显示
    
    // iOS系统坐标系
    // 1 与数学中的坐标系不同, y的正方向是向下的
    // 2 原点是屏幕的左上角
    
    // frame bounds center(UIView的属性)
    // 1 frame (x, y, width, height) 视图在其父视图上的位置
    //    view.frame = CGRectMake(10, 10, 80, 80);
    // 2 bounds (x, y, width, height) 视图本身的坐标系
    // 3 center 中心点
#pragma mark - bounds
    // bounds x, y修改本身的坐标系, 影响它的子视图
    // bounds width, height修改的是本身大小,会以中心点收缩/扩张
    // bounds 的改变, 不会改变该视图的位置
    // bounds 的 x, y影响子视图的frame, 改变坐标系
    NSLog(@"改变bounds前的frame%@", NSStringFromCGRect(view.frame));
    NSLog(@"center%@", NSStringFromCGPoint(view.center));
    view.bounds = CGRectMake(10, 10, 80, 80);
    NSLog(@"改变bounds后的frame%@", NSStringFromCGRect(view.frame));
    NSLog(@"center%@", NSStringFromCGPoint(view.center));
    
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    subView.backgroundColor = [UIColor redColor];
    [view addSubview:subView];
    
#pragma mark - 改变view的frame
    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, 100, view.frame.size.height);
    // view.frame getter方法
    // frame.size 结构体
    // OC和C的内容结合, 是一个常量
//    view.frame.size.width = 100;
    view.z_x = 100;
    CGRect rect = view.frame;
    rect.size.width = 100;
    view.frame = rect;
     */
    
#pragma mark - UIView的基本属性
    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    testView.backgroundColor = [UIColor yellowColor];
    [_window addSubview:testView];
    // 透明度 0.0 ~ 1.0
    testView.alpha = 0.8;
    // tag 标记(编号)
    testView.tag = 1000;
    // 根据tag获取到对应的view __kindof
    UIView *view1 = [_window viewWithTag:1000];
    // subViews
    NSArray *viewArr = _window.subviews;
    // superView
    UIView *supView = testView.superview;
    // hidden 隐藏/显示
    
    /**
     *  视图层级
     * addSubview
     * insertSubview:atIndex
     * insertSubview:aboveSubview
     * insertSubview:belowSubview
     */
    UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    firstView.backgroundColor = [UIColor blueColor];
    // 添加视图
    [_window addSubview:firstView];
    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
    secondView.backgroundColor = [UIColor redColor];
    // insertSubview: atIndex:(插入视图, 到指定下标)
    [_window insertSubview:secondView atIndex:2];
    // 插入视图,到指定视图之上 insertSubview: aboveSubview
    UIView *lastView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
    lastView.backgroundColor = [UIColor cyanColor];
    [_window insertSubview:lastView aboveSubview:secondView];
    // 插入视图, 到指定视图之下 insertSubview: belowSubview
    [_window insertSubview:lastView belowSubview:secondView];
    
#pragma mark - UILabel
    // 如果类没有自己的初始化方法, 使用父类的
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 100)];
    label.backgroundColor = [UIColor yellowColor];
    [_window addSubview:label];
    
    // label的属性
    // 1 text
    label.text = @"我是韩旭";
    // 2 textColor
    label.textColor = [UIColor purpleColor];
    // 3 font 默认值 17
    label.font = [UIFont systemFontOfSize:18.0];
    label.font = [UIFont boldSystemFontOfSize:20.0];
    // 4 textAlignment 对齐方式 默认对齐方式NSTextAlignmentLeft
    label.textAlignment = NSTextAlignmentRight;
    // 5 numberOfLines 默认为1
    // 不确定行数时 给0
    label.numberOfLines = 1;
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
